//
//  UIView+ZTQuickControl.m
//  BlockUseDemo
//
//  Created by quiet on 15/7/15.
//  Copyright (c) 2015年 quiet. All rights reserved.
//

#import "UIView+ZTQuickControl.h"


@implementation UIView (ZTQuickControl)



//!@brief 快速添加一个系统按钮
-(UIButton *)addSystemButtonWithFrame:(CGRect)frame
                           title:(NSString *)titile
                          action:(void(^)(ZTButton *button))action
{
    ZTButton *button = [ZTButton buttonWithType:UIButtonTypeSystem];
    
    button.frame = frame;
    
    [button setTitle:titile forState:UIControlStateNormal];
    
    button.action = action;
    
    [self addSubview:button];
    
    return button;
}

//!@brief 类方法添加一个系统按钮
+(UIButton *)CreateSystemButtonWithFrame:(CGRect)frame
                                title:(NSString *)titile
                               action:(void(^)(ZTButton *button))action
{
    ZTButton *button = [ZTButton buttonWithType:UIButtonTypeSystem];
    
    button.frame = frame;
    
    [button setTitle:titile forState:UIControlStateNormal];
    
    button.action = action;
    
    return button;
}

//!@brief 创建图片按钮
-(UIButton *)addImageButtonWithFrame:(CGRect)frame
                               title:(NSString *)titile
                               image:(NSString *)image
                              action:(void(^)(ZTButton *button))action
{
    ZTButton *button = [ZTButton buttonWithType:UIButtonTypeCustom];
    
    button.frame = frame;
    
    [button setTitle:titile forState:UIControlStateNormal];
    
    [button setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    
    button.action = action;
    
    [self addSubview:button];
    
    return button;
}

//!@brief 类方法创建图片按钮
+(UIButton *)CreateImageButtonWithFrame:(CGRect)frame
                                  title:(NSString *)titile
                                  image:(NSString *)image
                                 action:(void(^)(ZTButton *button))action
{
    ZTButton *button = [ZTButton buttonWithType:UIButtonTypeCustom];
    
    button.frame = frame;
    
    [button setTitle:titile forState:UIControlStateNormal];
    
    [button setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    
    button.action = action;
    
    return button;
}

//!@brief 创建label
-(UILabel *)addLabelWithFrame:(CGRect)frame
                        title:(NSString *)title
{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    
    label.text = title;
    
    [self addSubview:label];
    
    return label;
}

//!@brief 类方法创建label
+(UILabel *)CreateLabelWithFrame:(CGRect)frame
                        title:(NSString *)title
{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    
    label.text = title;
    
    return label;
}

//!@brief 创建imageView
-(UIImageView *)addImageViewWithFrame:(CGRect)frame
                                image:(NSString *)image
{
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
    
    imageView.image = [UIImage imageNamed:image];
    
    [self addSubview:imageView];
    
    return imageView;
}

//!@brief 类方法创建imageView
+(UIImageView *)CreateImageViewWithFrame:(CGRect)frame
                                image:(NSString *)image
{
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
    
    imageView.image = [UIImage imageNamed:image];
    
    return imageView;
}

//!@brief 创建textfiled
-(UITextField *)addTextFieldWithFrame:(CGRect)frame
                                style:(UITextBorderStyle)style
                             delegate:(id)delegate
{

    UITextField *textField = [[UITextField alloc] initWithFrame:frame];
    
    textField.borderStyle = style;
    
    textField.delegate = delegate;
    
    [self addSubview:textField];
    
    return textField;
    
}


//!@brief 类方法创建textfiled
+(UITextField *)CreateTextFieldWithFrame:(CGRect)frame
                                style:(UITextBorderStyle)style
                             delegate:(id)delegate
{
    UITextField *textField = [[UITextField alloc] initWithFrame:frame];
    
    textField.borderStyle = style;
    
    textField.delegate = delegate;
    
    return textField;
}

//!@brief 添加一个tableView
-(ZTTableView*)addTableViewWithRect:(CGRect)rect
                          withStyle:(UITableViewStyle)style
{
    //表格创建
    ZTTableView* tableView = [[ZTTableView alloc]initWithFrame:rect withStyle:UITableViewStylePlain];
 
    [self addSubview:tableView];
    
    return tableView;
}

//!@brief 类方法创建一个tableView
+(ZTTableView*)addTableViewWithRect:(CGRect)rect
                          withStyle:(UITableViewStyle)style
{
    //表格创建
    ZTTableView* tableView = [[ZTTableView alloc]initWithFrame:rect withStyle:UITableViewStylePlain];
    
    return tableView;
}

@end
